package name.nano.server;


import java.util.ArrayList;
import java.util.Iterator;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import javax.jdo.annotations.IdentityType;

import name.nano.client.dto.PlayerTactic;
import name.nano.client.dto.TeamTactic;
import name.nano.client.utils.Coordinate;



@PersistenceCapable(identityType = IdentityType.APPLICATION) 
public class TeamTacticDAO  {
	private static final int ENDZONE_LENGHT = 23;
	private static final int FIELD_WIDTH = 34;
	public static final int FIELD_LENGHT = 110;
    
	@Persistent
	private ArrayList<PlayerTacticDAO> playersTactic;

	//private final Location fieldSize;

	@Persistent
	private int playerWithDisk;
	
	
	@Persistent
	private String m_tacticName;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	Long key;
	
	public TeamTacticDAO(){
		
	}
	public TeamTactic getDTO(){
		ArrayList<PlayerTacticDAO> playersTactic2 = getPlayersTactic();
		ArrayList<PlayerTactic> pt=new ArrayList<PlayerTactic>();
		for (Iterator<PlayerTacticDAO> iterator = playersTactic2.iterator(); iterator.hasNext();) {
			PlayerTacticDAO playerTacticDAO = (PlayerTacticDAO) iterator.next();
			pt.add(playerTacticDAO.getDTO());
		}
		

		return new TeamTactic(getTacticName(),pt);
	}


	public String getTacticName() {
		return m_tacticName;
	}

	public void setTacticName(String name) {
		m_tacticName = name;
	}

	public ArrayList<PlayerTacticDAO> getPlayersTactic() {
		return playersTactic;
	}

	public Coordinate getFieldSize() {
		return new Coordinate(FIELD_WIDTH,FIELD_LENGHT);
	}

	public int getBaselineDefence() {
		return (int) (getFieldSize().y*(ENDZONE_LENGHT/(double)FIELD_LENGHT));
	}

	public int getBaselineOffence() {
		return (int) (getFieldSize().y*((FIELD_LENGHT-ENDZONE_LENGHT)/(double)FIELD_LENGHT));
	}

	public int getPlayerWithDisk() {
		return playerWithDisk;
	}

	public void setPlayerWithDisk(int playerWithDisk) {
		this.playerWithDisk = playerWithDisk;
	}

	public void setPlayerList(ArrayList<PlayerTacticDAO> pt) {
		playersTactic=pt;
		
	}
	
	
}
